<template>
  <div class="app-container">
    <el-row :gutter="20" class="header">
      <!-- 
      <el-button type="success" :icon="DocumentAdd" @click="handleDialogValue()"
        v-if="hasAuth('system:user:add')">新增</el-button> -->

    </el-row>
    <el-table :data="dataList" stripe style="width: 100%">
      <el-table-column prop="id" label="日志ID" align="center" />
      <el-table-column prop="text" label="日志信息" align="center" />
      <el-table-column prop="createTime" label="时间" align="center">
        <template v-slot="scope">
          {{ ChangeDateFormat(scope.row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column prop="action" label="操作" width="400" fixed="right" align="center">
        <template v-slot="scope">

          <!-- <el-button v-if="scope.row.username != 'admin' && hasAuth('system:user:edit')" type="primary" :icon="Edit"
            @click="handleDialogValue(scope.row.id)" /> -->

          <el-popconfirm v-if="scope.row.username != 'admin'" title="您确定要删除这条记录吗？" @confirm="handleDelete(scope.row.id)">
            <template #reference>
              <el-button type="danger" :icon="Delete" v-if="hasAuth('system:user:delete')" />
            </template>
          </el-popconfirm>


        </template>
      </el-table-column>

    </el-table>
    <el-pagination v-model:currentPage="queryForm.pageNum" v-model:page-size="queryForm.pageSize"
      :page-sizes="[5, 10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper" :total="total"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
  <Dialog v-model="dialogVisible" :dialogVisible="dialogVisible" :id="id" :dialogTitle="dialogTitle" :isUpdate="isUpdate"
    @initUserList="initUserList"></Dialog>
</template>
  
<script setup>
import { Search, Delete, Refresh, DocumentAdd, Edit, Tools, RefreshRight } from '@element-plus/icons-vue'
import { ref } from 'vue'
import requestUtil, { getServerUrl } from "@/utils/request";
import { ElMessage, ElMessageBox } from 'element-plus'
import Dialog from './components/dialog'

const id = ref(-1)
const dialogVisible = ref(false)
const dialogTitle = ref('')
const isUpdate = ref(true)

const queryForm = ref({
  param: {},
  pageNum: 1,
  pageSize: 10
})
const total = ref(0)
const dataList = ref([])

const ChangeDateFormat = (datee) => {
  let date = new Date(datee)
  var YY = date.getFullYear() + "-"
  var MM = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"
  var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  var hh = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  var mm = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return YY + MM + DD + " " + hh + mm + ss;
}
const initUserList = async () => {
  const res = await requestUtil.post("/ylz/cms-log/cms-log/listPage", queryForm.value)
  dataList.value = res.data.data
  total.value = res.data.total
}
initUserList()

const handleSizeChange = (pageSize) => {
  queryForm.value.pageNum = 1;
  queryForm.value.pageSize = pageSize;
  initUserList();
}

const handleCurrentChange = (pageNum) => {
  queryForm.value.pageNum = pageNum;
  initUserList();
}

const handleDelete = async (id) => {

  const res = await requestUtil.get("/ylz/cms-log/cms-log/del", { id })
  if (res.data.code == 200) {
    ElMessage({
      type: 'success',
      message: '执行成功!'
    })
    initUserList();
  } else {
    ElMessage({
      type: 'error',
      message: res.data.msg,
    })
  }
}

const handleDialogValue = (dataId) => {
  if (dataId) {
    id.value = dataId;
    dialogTitle.value = "数据修改"
  } else {
    id.value = -1;
    dialogTitle.value = "数据新增"

  }
  dialogVisible.value = true
}


</script>
  
<style scoped></style>
  